<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const mypromise = (params) => {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          console.log(" setTimeout = ", params);
          // resolve(params);
          throw "reject 11"
          // reject(params)
        }, 10);
      })
    }
    // resolve times
    const mypromise1 = (params) => {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          console.log(1)
          resolve(1);
          console.log(2)
          resolve(2);
          console.log(3)
          resolve(3);
        }, 10);
      })
    }
    mypromise1().then(res => {
      console.log(` mypromise1 perform = ${res} `)
    })
    const immediatePromise = () => {
      return Promise.resolve(() => {
        console.log(" immediatePromise - ")
      });
    }
    const runError = async () => {
      return Promise.reject(" === runError === ")
    }
    async function runMain() {
      console.log(" before -- mypromise ")

      // await mypromise("mypromise").then((params) => {
      //   console.log(" mypromise - perform ")
      // });
      let mypromisea;
      try {
        console.log(" 0 - ")
        // mypromisea = await mypromise("mypromise");
        // mypromisea = mypromise("mypromise");
        // await immediatePromise().then();
        // await immediatePromise().then((par) => {
        // console.log(par)
        // });

        await runError();
        console.log(" - 1 - ")
        // mypromisea.catch((err) => {
        //   console.log(" reject -- err --- ", err)
        // })
      } catch (error) {
        console.log(" mypromise - perform -- err ", error)
      }

      // console.log(" mypromise - perform ", mypromisea)
      // console.log(" after -- mypromise ")
    }

    runMain();
  </script>
</body>

</html>